/*
 * KDMTrackingAction.cpp
 *
 *  Created on: Jul 22, 2011
 *      Author: blyth
 */

#include <KDMTrackingAction.hh>
#include <KDMTrackingInfo.hh>
#include <G4TrackingManager.hh>
#include <G4Track.hh>
#include <KDMGlobals.hh>
#include <iostream>
using namespace std;

KDMTrackingAction::KDMTrackingAction() {
	;
}

KDMTrackingAction::~KDMTrackingAction() {
	;
}

void KDMTrackingAction::PreUserTrackingAction(const G4Track* track) {
	G4String volName = track->GetVolume()->GetName();
	G4String particleName = track->GetParticleDefinition()->GetParticleName();
	if (track->GetUserInformation() == 0) {
		KDMTrackingInfo* info = new KDMTrackingInfo();
		if (volName.contains("Veto")) {
			info->setOriginatedFromCV(true);
			if (/*track->GetParticleDefinition()->GetPDGCharge() == 0*/true) {
				tempSS << particleName << endl;
			} else {
				CV = true;
			}
		}
		fpTrackingManager->SetUserTrackInformation(info);
	} else {
		if (volName.contains("Veto")) {
			((KDMTrackingInfo*) track->GetUserInformation())->setOriginatedFromCV(true);
			if (/*track->GetParticleDefinition()->GetPDGCharge() == 0*/true) {
				tempSS << particleName << endl;
			} else {
				CV = true;
			}
		}
	}
}

void KDMTrackingAction::PostUserTrackingAction(const G4Track* track) {
	G4TrackVector* secondaries = fpTrackingManager->GimmeSecondaries();
	if (secondaries) {
		KDMTrackingInfo* info = (KDMTrackingInfo*) (track->GetUserInformation());
		size_t nSeco = secondaries->size();
		if (nSeco > 0)
			for (size_t i = 0; i < nSeco; i++)
				(*secondaries)[i]->SetUserInformation(new KDMTrackingInfo(info));
	}
}
